package com.bhs.sansonglogistics.ui.waybill;

import static android.content.Context.CLIPBOARD_SERVICE;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.view.View;
import android.widget.TextView;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.WaybillDetailsBean;
import com.bhs.sansonglogistics.utils.DateUtils;
import com.bhs.sansonglogistics.utils.ToastUtil;

/**
 * 运单详情和运单调整复用字段
 */
public class WaybillReuse implements View.OnClickListener {

    private TextView mTvWaybillNumber;//运单号
    private TextView mTvDepartureTime;//发车时间
    private TextView mTvOrderNumber;//订单数量
    private TextView mTvDepartureCity;//出发城市
    private TextView mTvArrivalCity;//到达城市


    private TextView mTvSendCompany;//发站公司
    private TextView mTvLineManager;//专线经理
    private TextView mTvManagerPhoneNumber;//经理手机
    private TextView mTvSendAddress;//发站地址


    private ClipData mClipData;   //剪切板Data对象
    private ClipboardManager mClipboardManager;   //剪切板管理工具类
    private Activity activity;

    public void initView(Activity activity) {
        this.activity = activity;
        // 1. 注册mClipboardManager
        mClipboardManager = (ClipboardManager) activity.getSystemService(CLIPBOARD_SERVICE);
        mTvWaybillNumber = activity.findViewById(R.id.tv_waybill_number);
        mTvWaybillNumber.setOnClickListener(this);
        mTvDepartureTime = activity.findViewById(R.id.tv_departure_time);

        mTvSendCompany = activity.findViewById(R.id.tv_send_company);
        mTvLineManager = activity.findViewById(R.id.tv_line_manager);
        mTvManagerPhoneNumber = activity.findViewById(R.id.tv_manager_phone_number);
        mTvSendAddress = activity.findViewById(R.id.tv_send_address);
        mTvOrderNumber = activity.findViewById(R.id.tv_order_number);
        mTvDepartureCity = activity.findViewById(R.id.tv_departure_city);
        mTvArrivalCity = activity.findViewById(R.id.tv_arrival_city);

    }

    public void initData(WaybillDetailsBean.DataDTO waybillData) {
        WaybillDetailsBean.DataDTO.WaybillInfoDTO data = waybillData.getWaybill_info();
        mTvWaybillNumber.setText(String.format("运单号：%s", data.getWaybill_sn()));
        mTvDepartureTime.setText(String.format("发车时间：%s", DateUtils.getTime(data.getCreate_time())));
        mTvOrderNumber.setText(String.format("订单：%s单", waybillData.getDeliver_order_count()));
        mTvDepartureCity.setText(data.getLine_start_city());
        mTvArrivalCity.setText(data.getLine_end_city());


        mTvSendCompany.setText(String.format("发站公司：%s", waybillData.getLogistics_info().getCompany_name()));
        mTvLineManager.setText(String.format("专线经理：%s", waybillData.getLine_info().getLine_contact()));
        mTvManagerPhoneNumber.setText(String.format("经理手机：%s", waybillData.getLine_info().getLine_mobile()));
        mTvSendAddress.setText(String.format("发站地址：%s", waybillData.getLogistics_info().getAddress()));
    }


    @Override
    public void onClick(View view) {
        //创建一个新的文本clip对象
        mClipData = ClipData.newPlainText("Simple text", activity.getIntent().getStringExtra("waybill_sn"));
        //把clip对象放在剪贴板中
        mClipboardManager.setPrimaryClip(mClipData);
        ToastUtil.show("复制成功");
    }
}
